﻿#include "mainwindowa.h"
#include "ui_mainwindowa.h"

#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif

MainWindowA::MainWindowA(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindowA), model(new QStandardItemModel(0, 8, this))
{
    ui->setupUi(this);
    ui->treeView->setModel(model);
    costomDleget = new KLCustomDelegate(ui->treeView);
    ui->treeView->setItemDelegate(costomDleget);

    // 设置表头
   // model->setHorizontalHeaderLabels({"Column 1", "Column 2", "Column 3", "Column 4", "Column 5", "Column 6", "Column 7", "Column 8"});

    // 创建根节点
    QStandardItem *rootItem = model->invisibleRootItem();

    // 创建父节点
    QStandardItem *parentItem = new QStandardItem("Parent Node");
    parentItem->setIcon(QIcon(":/Resource/group.png"));

    // 创建子节点
    QStandardItem *childItem1 = new QStandardItem("Child 1");
    QStandardItem *childItem2 = new QStandardItem("Child 2");
    QStandardItem *childItem3 = new QStandardItem("子节点 3");
    QStandardItem *childItem4 = new QStandardItem("子节点 4");
    QStandardItem *childItem5 = new QStandardItem("子节点 5");
    QStandardItem *childItem6 = new QStandardItem("子节点 6");
    QStandardItem *childItem7 = new QStandardItem("子节点 7");
    QStandardItem *childItem8 = new QStandardItem("子节点 8");
    

    // 将子节点添加到父节点
    parentItem->appendRow({childItem1, childItem2, childItem3, childItem4, childItem5, childItem6, childItem7, childItem8});

    // 创建另一个父节点
    QStandardItem *parentItem2 = new QStandardItem("Parent Node 2");

    // 创建子节点
    QStandardItem *childItem21 = new QStandardItem("Child 21");
    QStandardItem *childItem22 = new QStandardItem("Child 22");
    QStandardItem *childItem23 = new QStandardItem("Child 23");
    QStandardItem *childItem24 = new QStandardItem("Child 24");
    QStandardItem *childItem25 = new QStandardItem("Child 25");
    QStandardItem *childItem26 = new QStandardItem("Child 26");
    QStandardItem *childItem27 = new QStandardItem("Child 27");
    QStandardItem *childItem28 = new QStandardItem("Child 28");

    // 将子节点添加到父节点
    parentItem2->appendRow({childItem21, childItem22, childItem23, childItem24, childItem25, childItem26, childItem27, childItem28});

    // 将父节点添加到根节点
    rootItem->appendRow(parentItem);
    rootItem->appendRow(parentItem2);

    // 设置自定义表头数据
    QMap<int, QVariant> headerData;
    headerData[0] = QVariant::fromValue(QMap<QString, QVariant>({
        {"text", "sim_KLSHGDJS334采集卡信息"},
        {"icon", ""} // 替换为你的图标路径
    }));
    headerData[1] = QVariant::fromValue(QMap<QString, QVariant>({
        {"text", "名称"},
        {"icon", ":/Resource/名称.png"} // 替换为你的图标路径
    }));
    headerData[2] = QVariant::fromValue(QMap<QString, QVariant>({
        {"text", "启用"},
        {"icon", ":/Resource/启用.png"} // 替换为你的图标路径
    }));

    headerData[3] = QVariant::fromValue(QMap<QString, QVariant>({
        {"text", "分组"},
        {"icon", ":/Resource/分组.png"} // 替换为你的图标路径
    }));

    headerData[4] = QVariant::fromValue(QMap<QString, QVariant>({
        {"text", "分辨率"},
        {"icon", ":/Resource/分辨率.png"} // 替换为你的图标路径
    }));

    headerData[5] = QVariant::fromValue(QMap<QString, QVariant>({
        {"text", "采集卡输出1"},
        {"icon", ":/Resource/采集输出1.png"} // 替换为你的图标路径
    }));

    headerData[6] = QVariant::fromValue(QMap<QString, QVariant>({
        {"text", "采集卡输出2"},
        {"icon", ":/Resource/采集输出2.png"} // 替换为你的图标路径
    }));

    headerData[7] = QVariant::fromValue(QMap<QString, QVariant>({
        {"text", "类型"},
        {"icon", ":/Resource/类型.png"} // 替换为你的图标路径
    }));


    // 设置自定义表头视图
    headerView = new CustomHeaderView(Qt::Horizontal, this);
    headerView->setHeaderData(headerData);
    headerView->setBackgroundColor("#729ec4");

    ui->treeView->setHeader(headerView);

//    QStandardItemModel *model = new QStandardItemModel(this);
//    ui->treeView->setModel(model);


//    // 设置表头
//    QStringList headerLabels;
//    headerLabels << "Column 1" << "Column 2" << "Column 3";
//    model->setHorizontalHeaderLabels(headerLabels);
    // 设置表头的初始大小
    ui->treeView->header()->resizeSection(0, 200); // 第一列宽度为200
    ui->treeView->header()->resizeSection(1, 150); // 第二列宽度为150
    ui->treeView->header()->resizeSection(2, 150); // 第三列宽度为150
    ui->treeView->header()->resizeSection(3, 200); // 第一列宽度为200
    ui->treeView->header()->resizeSection(4, 150); // 第二列宽度为150
    ui->treeView->header()->resizeSection(5, 150); // 第三列宽度为150
    ui->treeView->header()->resizeSection(6, 200); // 第一列宽度为200
    ui->treeView->header()->resizeSection(7, 150); // 第二列宽度为150

    // 手动设置表头高度
    headerView->setSectionHeight(0, 50); // 设置第一列的高度为80
    headerView->setSectionHeight(1, 50); // 设置第二列的高度为60
    headerView->setSectionHeight(2, 50); // 设置第三列的高度为70
    headerView->setSectionHeight(3, 50); // 设置第一列的高度为80
    headerView->setSectionHeight(4, 50); // 设置第二列的高度为60
    headerView->setSectionHeight(5, 50); // 设置第三列的高度为70
    headerView->setSectionHeight(6, 50); // 设置第一列的高度为80
    headerView->setSectionHeight(7, 50); // 设置第二列的高度为60

    // 设置布局
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(ui->treeView);

    QWidget *centralWidget = new QWidget(this);
    centralWidget->setLayout(layout);
    setCentralWidget(centralWidget);
}

MainWindowA::~MainWindowA()
{
    delete ui;
}



/**********QTreeView**********/
/*
QHeaderView::section {
    height:25px;
    color:white;
    background:#505050;
    border-left:0px solid gray;
    border-right:1px solid gray;
    border-top:0px solid gray;
    border-bottom:0px solid gray;
}

QTreeView {
    border:none;
    background: #404040;
    show-decoration-selected: 1;
}
QTreeView::item {
    height: 25px;
    border: none;
    color: white;
    background: transparent;
}
QTreeView::item:hover {
    background: transparent;
}
QTreeView::item:selected{
    background: #1E90FF;
}
QTreeView::branch {
    background: transparent;
}
QTreeView::branch:hover {
    background: transparent;
}
QTreeView::branch:selected {
    background: #1E90FF;
}
QTreeView::branch:closed:has-children{
    image: url(:/image/treeclose.png);
}
QTreeView::branch:open:has-children{
    image: url(:/image/treeopen.png);
}
*/
